Imports System.Data
Imports System.Security.Cryptography

Partial Class Client_frmLogin
    Inherits System.Web.UI.Page
    Dim _BO As New Bo
    Dim flag As Boolean = True
    Dim dtable As New DataTable
    Dim _UserId As String
    Dim _Password As String
    Dim _EmployeeId As String
    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        clearall()
    End Sub
    Public Sub clearall()
        txtPassword.Text = ""
        txtUserId.Text = ""
    End Sub
    Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        If ddlLog.SelectedValue = "ADMIN" Then
            checkadmin()
        Else
            checkclient()
        End If
    End Sub
    Sub checkadmin()
        Dim md5Hasher As MD5 = MD5.Create()
        Dim data As Byte() = md5Hasher.ComputeHash(Encoding.[Default].GetBytes(txtPassword.Text))
        Dim sBuilder As New StringBuilder()
        For i As Integer = 0 To data.Length - 1
            sBuilder.Append(data(i).ToString("x2"))
        Next
        _EmployeeId = txtUserId.Text
        _Password = sBuilder.ToString()
        dtable = _BO.CheckEmployee(_EmployeeId, _Password)
        If dtable.Rows.Count = 0 Then
            flag = False
            MsgBox("Incorrect Login Or Incorrect Password")
            clearall()
            Exit Sub
        End If
        If (dtable.Rows(0).Item(0).ToString = _EmployeeId Or dtable.Rows(0).Item(1).ToString = _Password) And flag = True Then
            Session("EmpId") = txtUserId.Text
            Response.Redirect("../Admin/frmHome.aspx")
        End If
    End Sub
    Sub checkclient()

        Dim md5Hasher As MD5 = MD5.Create()
        Dim data As Byte() = md5Hasher.ComputeHash(Encoding.[Default].GetBytes(txtPassword.Text))
        Dim sBuilder As New StringBuilder()
        For i As Integer = 0 To data.Length - 1
            sBuilder.Append(data(i).ToString("x2"))
        Next
        _UserId = txtUserId.Text
        _Password = sBuilder.ToString()
        dtable = _BO.CheckUser(_UserId, _Password)
        If dtable.Rows.Count = 0 Then
            flag = False
            MsgBox("Incorrect Login Or Incorrect Password")
            clearall()
            txtUserId.Focus()
            Exit Sub
        End If
        If (dtable.Rows(0).Item(0).ToString = _UserId Or dtable.Rows(0).Item(1).ToString = _Password) And flag = True Then
            _BO.DeleteCartDetail()
            _BO.DeleteCartMaster()
            Session("UserId") = txtUserId.Text
            Response.Redirect("frmDataList.aspx")
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        txtUserId.Focus()
    End Sub


End Class
